

{block name="content"}
<div  class="think-box-shadow">
    <fieldset>
        <legend>条件搜索</legend>
        <form class="layui-form layui-form-pane form-search" method="get" autocomplete="off">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">企业名称</label>
                <div class="layui-input-inline">
                    <input name="search-qiye-name" value="" placeholder="请输入名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <button onclick="doSearch(1,true);" type="button" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
            </div>
        </form>
    </fieldset>
    <div style="min-height:260px;">
        <table class="layui-table" lay-skin="line">
            <thead>
            <tr>
                <th class='layui-hide-xs'>企业名称</th>
                <th class='layui-hide-xs'>联系人</th>
                <th class='layui-hide-xs'>联系电话</th>
                <th class='layui-hide-xs'>操作</th>
            </tr>
            </thead>
            <tbody name="list">

            </tbody>
            <tfoot name="page">
                <tr><td colspan="6">
                    <div id="pagingBox"></div>
                </td></tr>
            </tfoot>
            <tfoot name="tpl" style="display: none;">
            <tr>
                <td class="nowrap">__NAME__</td>
                <td class="nowrap" >__CONTACTS__</td>
                <td class="nowrap" >__PHONE__</td>
                <td  class='text-center nowrap notselect'>
                    <a onclick="doChoice(__ID__,'__NAME__')" class="layui-btn layui-btn-xs">选择</a>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
{/block}
<script>

    doSearch(1, paging=true);

    function doSearch(page=1) {
        var name = $("input[name=search-qiye-name]").val();
        $.post("/cms/qiyemanufacturer/ajaxSearch",{name:name,page:page},function(res) {
            $("tbody[name=list]").html(render(res.data.list));
            if(paging==true)
                doPaging(page, res.data.limit, res.data.total);
        },"json");
    
        function doPaging(currPage, itemsPerPage, itemTotal) {
            layui.use('laypage', function(){
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                    elem: 'pagingBox'
                    ,count: itemTotal //数据总数，从服务端得到
                    ,limit:itemsPerPage
                    ,curr: currPage
                    ,jump: function(obj, first){
                        if(page!=obj.curr){
                            doSearch(obj.curr, false);
                        }
                        //obj包含了当前分页的所有参数，比如：
                        console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                    }
                });
            });
        }
        
        function render(data) {
            var list = "";
            for(var i=0; i<data.length; i++){
                var html = $("tfoot[name=tpl]").html();
                html = html.replace("__ID__", data[i].id);
                html = html.replace("__NAME__", data[i].name);
                html = html.replace("__NAME__", data[i].name);
                html = html.replace("__CONTACTS__", data[i].contacts);
                html = html.replace("__PHONE__", data[i].phone);
                list += html;
            }
            return list;
        }


    }


    
</script>

